<?
include_once '/var/www/html/new/com.inc.php';
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$aid=$_SESSION['sid'];
$lids=$_REQUEST['type']? $_REQUEST['type']:'';
$btime=$_POST['bt']? $_POST['bt']:date('Y-m-d',strtotime("-30days"));
$etime=$_POST['et']? $_POST['et']:date('Y-m-d');
$bt= $btime .' 00:00:00';
$et = $etime .' 23:59:59';
$lid_arr=array();
//获取景区存于$lid_arr中
$x_ob1 = simplexml_load_string($s -> Order_Globle_Search(
    "","$aid", "", "", "", "", "$bt", "$et", "", "",
    "", "", "", "", "", "1", "", "", "1", "1",
    "0", "1000", "0", "0","","0","0", "0","","",
    "", "", "", "", ""));

foreach($x_ob1->Rec as $key1=>$val1){
    if($val1->UUpmode==3){
    $lid_arr[(string)$val1->UUlid]=$val1->UUltitle;
    }
}

$x_ob2 = simplexml_load_string($s -> Order_Globle_Search(
    "","", "", "", "", "", "$bt", "$et", "", "",
    "", "", "", "", "", "1", "", "", "1", "1",
    "0", "1000", "0", "0","","0","0", "0","","",
    "$aid", "", "", "", ""));
//print_r($x_ob2);
foreach($x_ob2->Rec as $key2=>$val2){
    $lid_arr[ (string)$val2->UUlid ]=$val2->UUltitle;

 }

$lid_arr=array_unique($lid_arr);

for($date = $btime;$date <= $etime;$date = date('Y-m-d',strtotime($date)+86400)){
    $st = $date .' 00:00:00';
    $et = $date .' 23:59:59';
    //获取自销的票数
    $x2 = simplexml_load_string($s -> Order_Globle_Search(
        "","$aid", "$lids", "", "", "", "$st", "$et", "", "",
        "", "", "", "", "", "", "", "", "1", "1",
        "0", "800", "0", "0","","0","0", "0","","",
        "$aid", "", "", "", ""));
    //$selft=0;
    //print_r($x2);
    foreach($x2->Rec as $k=>$v){
        $vb=(int)$v->UUpmode;
        if($vb==3){
            $selft+=(int)$v->UUtnum;
        }
    }
    //echo $var;
    $titname = simplexml_load_string($s -> Order_Globle_Search(
        "","", "$lids", "", "", "", "$st", "$et", "", "",
        "", "", "", "", "", "", "", "", "1", "1",
        "0", "800", "0", "0","","0","0", "0","","",
        "$aid", "", "", "", ""));
    //根据购买者类型进行累加
    // print_r($titname);
    foreach($titname->Rec as $key=>$val)
    { //$ylid2[$v->UUltitle]=(string)$val->UUlid;
        //$sum+=(int)$val->UUtnum;
        $c_type="select fid,com_type from pft_member_extinfo where fid=$val->UUmid";
        $GLOBALS['le']->query($c_type);
        while($typerow=$GLOBALS['le']->fetch_assoc())
        {
            switch($typerow['com_type'])
            {case "团购": $teamt+=(int)$val->UUtnum;break;//暂未加入
                case "旅行社": $lvt+=(int)$val->UUtnum;break;
                case "淘宝/天猫": $taot+=(int)$val->UUtnum;break;
                //case "景区": $selft+=(int)$val->UUtnum;break;//景区、酒店归为自销；
                //case "酒店": $selft+=(int)$val->UUtnum;break;
                //case "自销": $selft+=(int)$val->UUtnum;break;
                case "电商/团购网": $dtt+=(int)$val->UUtnum;break;//归为OTA；
                default : $otht+=(int)$val->UUtnum;break;//除以上之外归为其他；

            }

        }
    }

}





//取大于0的票数
$team_arr['团购']=$teatt>0? $teamt:'';
$lvt_arr['旅行社']=$lvt>0? $lvt:'';
$taot_arr['淘宝/天猫']=$taot>0? $taot:'';
$selft_arr['自销']=$selft>0? $selft:'';
$dtt_arr['OTA']=$dtt>0? $dtt:'';
$otht_arr['其他']=$otht>0? $otht:'';

//合并数组输出json格式；
$mer_arr=array_merge($team_arr,$lvt_arr,$taot_arr,$selft_arr,$dtt_arr,$otht_arr);
foreach($mer_arr as $names=>$tict){
    if($tict>0){
        $tictstr.="{value:".$tict.", "."name:"."'".$names."'"."},";

    }
}
$tictstr=substr($tictstr,0,-1);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>
<body>
<form action="http://www.12301.cc/tpl/zpie2.html" method="post"  name="form" >
    <select id="bindList" class="selectcss" name="type">
        <?
        if($lid_arr){
            foreach($lid_arr as $lid=>$v){
                ?>
                <option value="<?=$lid?>" <?if($_REQUEST['type']==$lid)echo 'selected="selected"'?>><?=$v?></option>
            <?}}else{?>
            <option value='' >请选择选项</option>
        <?}?>
    </select>
    <span class="lt">活动时间：</span>
    <input type="text" data-t="bt" id="txtStartTime" value="<?=$_REQUEST['bt']?>" name="bt" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/> 至
    <input type="text" data-t="et" id="txtEndTime"  value="<?=$_REQUEST['et']?>" name="et" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/>
    <input type="submit" value="提交">
</form>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="height:400px;width:800px"></div>
<!-- ECharts单文件引入 -->
<script src="//www.12301.cc/js/echarts-2.2.0/build/dist/echarts.js"></script>
<script language="javascript" src="http://www.12301.cc/js/WdatePicker.js"></script>
<script language="javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
<script src="http://www.12301.cc/js/select2.js"></script>
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/select2.css">
<script type="text/javascript">
    // 路径配置
    require.config({
        paths: {
            echarts: '//www.12301.cc/js/echarts-2.2.0/build/dist'
        }
    });

    // 使用
    require(
        [
            'echarts',
            'echarts/chart/pie',
            // 使用柱状图就加载bar模块
        ],
        function (ec) {
            // 基于准备好的dom，初始化echarts图表
            var myChart = ec.init(document.getElementById('main'));

            var option = {
                title : {
                    text: '分销商类型占比（饼形图）',

                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient : 'vertical',
                    x : 'left',
                    data:['OTA','团购','旅行社','淘宝/天猫','自销','其他']
                },
                toolbox: {
                    show : true,
                    feature : {

                        dataView : {show: true, readOnly: false},
                        magicType : {
                            show: false,
                            type: ['pie', 'funnel'],
                            option: {
                                funnel: {
                                    x: '25%',
                                    width: '50%',
                                    funnelAlign: 'left',
                                    max: 1548
                                }
                            }
                        },
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                series : [
                    {
                        name:'饼形图',
                        type:'pie',
                        radius : '55%',
                        center: ['50%', '60%'],
                        data:[



                            <?=$tictstr;?>
                        ]
                    }
                ]
            };
            // 为echarts对象加载数据
            myChart.setOption(option);
        }
    );


    $("#bindList").select2({
        placeholder: "Select a State",
        allowClear: true
    });
    $("#txtStartTime").bind("click focus", function () {

        var endtimeTf = $dp.$('txtEndTime');
        WdatePicker({
            maxDate: '#F{$dp.$D(\'txtEndTime\')}',
            dateFmt: "yyyy-MM-dd",
            onpicked: function () { endtimeTf.focus(); }
        });
    });
    $("#txtEndTime").bind("click focus", function () {
        WdatePicker({
            minDate: '#F{$dp.$D(\'txtStartTime\')}',
            dateFmt: "yyyy-MM-dd"
        });
    });
</script>
</body>
</html>